//
//  STBWViewController.m
//  stoneobs_browser
//
//  Created by shixuanlei on 06/26/2019.
//  Copyright (c) 2019 shixuanlei. All rights reserved.
//

#import "STFDViewController.h"
#import <stoneobs_browser/STBWBrowserKit.h>
#import <stoneobs_fakedata/STFDRandomImageProvider.h>
@interface STFDViewController ()<STBWBrowserViewControllerDelegate>
@property(nonatomic, strong) NSMutableArray<UIImageView*>                     *imagViewArray;/**<  */

@end

@implementation STFDViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self configSubView];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark --configSubView
- (void)configSubView{

    CGFloat top = 100;
    CGFloat inset = 5;
    CGFloat imageWitdh = (STBW_SCREEN_WIDTH - 4 * inset)/3;
    self.imagViewArray = NSMutableArray.new;
    for (NSInteger i = 0; i < 10; i ++ ) {
        UIImageView * imagView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, imageWitdh, imageWitdh)];
        UIImage * image = STFDRandomImageProvider.random_livegirl_image;
        imagView.image = image;
        imagView.contentMode = UIViewContentModeScaleAspectFill;
        imagView.clipsToBounds = YES;
        [self.view addSubview:imagView];
        imagView.stbw_left = inset + inset * (i%3) + imageWitdh * (i%3);
        imagView.stbw_top = top + inset * (i/3) + imageWitdh * (i/3);
        [self.imagViewArray addObject:imagView];
        imagView.tag = 10000 + i;
        imagView.userInteractionEnabled = YES;
        UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onSelctedImagView:)];
        [imagView addGestureRecognizer:tap];
    }
}
- (void)onSelctedImagView:(UITapGestureRecognizer*)tap{
    NSMutableArray * array = [NSMutableArray new];
    NSInteger num = self.imagViewArray.count;
    for (NSInteger i = 0; i<num; i ++) {
        STBWPhotoModel * model = [STBWPhotoModel new];
        model.originImage =self.imagViewArray[i].image;
        [array addObject:model];
    }
    STBWBrowserViewController * vc = [[STBWBrowserViewController alloc] initWithArray:array curentIndex:tap.view.tag-10000];
    vc.themeColor   = UIColor.greenColor;
    vc.delegate = self;
    vc.shouldHideBottomView = YES;
    [self presentViewController:vc animated:NO completion:nil];
    
}
#pragma mark --STBWBrowserViewControllerDelegate
- (UIView *)browserControllerDidScrollToIndexpath:(NSIndexPath *)indexPath model:(STBWPhotoModel *)model controller:(STBWBrowserViewController *)controller{
    return self.imagViewArray[indexPath.row];
}
- (void)willDismissFromSTPhotoSystemBrowserControllerCurrentIndexPath:(NSIndexPath *)currentIndexPath currentModel:(STBWPhotoModel *)currentModel controller:(STBWBrowserViewController *)controller{
    
}
- (void)didDismissFromSTPhotoSystemBrowserControllerCurrentIndexPath:(NSIndexPath *)currentIndexPath currentModel:(STBWPhotoModel *)currentModel controller:(STBWBrowserViewController *)controller{
    
}
- (void)rightBarActionFromController:(STBWBrowserViewController *)controller currentIndexPath:(NSIndexPath *)curentIndexpath{
    
}
@end
